package blue.qingyu.whimurmur.enhancement.function.infoShare;

import com.jfinal.aop.Inject;

import io.jboot.utils.CookieUtil;
import io.jboot.web.controller.JbootControllerContext;
import io.jboot.web.controller.annotation.RequestMapping;
import io.jpress.JPressConsts;
import io.jpress.model.User;
import io.jpress.service.UserService;
import io.jpress.web.base.TemplateControllerBase;

@RequestMapping("/infoShare/loginUser")
public class UserInfo extends TemplateControllerBase {
	@Inject
	UserService userService;
	
	public void getLoginUserInfo() {
		String uid = CookieUtil.get(JbootControllerContext.get(), JPressConsts.COOKIE_UID);

        User user = userService.findById(uid);
		
		if(user != null) {
			renderJson("{userAvatar:'" + user.getAvatar() + "', userName:'" + user.getNickname() + "'}");
		}else {
			renderFailJson();
		}
	}
}
